import {defineStore} from 'pinia'
import {ref} from 'vue'
import {getUserInfo} from '@/api/user.js'

export const useUserStore = defineStore('user', () => {
        const token = ref('')
        const userInfo = ref({})
        const setToken = (newToken) => {
                token.value = newToken
        }
        const getUser = async () => {
                const res = await getUserInfo()
                userInfo.value = res.data.data
        }
        const setUser = (obj) => {
                userInfo.value = obj
        }

        return {
                token,
                setToken,
                userInfo,
                getUser,
                setUser
        }
}, {
        persist: true
})
